package com.xiaoma.pattern.decorator;

/**
 * https://blog.csdn.net/qq_42665745/article/details/128369981
 * @author:maj
 * @created: 2024-11-05 09:05
 */
public class Main {

    public static void main(String[] args) {
        // 订一杯黑咖啡
        Coffee coffee = new BlackCoffee();
        System.out.println("订单：" + coffee.getDescription());
        System.out.println("总价：" + coffee.getCost());

        // 加牛奶
        coffee = new MilkDecorator(coffee);
        System.out.println("订单：" + coffee.getDescription());
        System.out.println("总价：" + coffee.getCost());

        // 再加糖
        coffee = new SugarDecorator(coffee);
        System.out.println("订单：" + coffee.getDescription());
        System.out.println("总价：" + coffee.getCost());

        // 加两份糖，一份奶的黑咖啡
        MilkDecorator coffee2 = new MilkDecorator(new SugarDecorator(new SugarDecorator(new BlackCoffee())));
        System.out.println("订单：" + coffee2.getDescription());
        System.out.println("总价：" + coffee2.getCost());
    }
}
